﻿//日历——————————————————————————————————————————
$(function () {
    //绘制月历体——————————————————————————————————————————

    for (var i = 0; i < 35; i++) {
        $("<li  style='width:26px; background-image:url(../Images/green-button.png);'><span></span></li>").appendTo(".month-body").addClass("month-cell");
    }

    var today = new Date()

    var FullYear = today.getFullYear(); //获取年份
    var m = today.getMonth();           //获取月号
    var month = today.getMonth() + 1;     //获取月份

    if (month == 1) month = "January";
    else if (month == 2) month = "February";
    else if (month == 3) month = "March";
    else if (month == 4) month = "April";
    else if (month == 5) month = "May";
    else if (month == 6) month = "June";
    else if (month == 7) month = "July";
    else if (month == 8) month = "August";
    else if (month == 9) month = "September";
    else if (month == 10) month = "October";
    else if (month == 11) month = "November";
    else if (month == 12) month = "December";
    else month = "";

    if (month < 10) {
        month = "0" + month;
    }
    var date = today.getDate();       //获取日期
    var day = today.getDay();           //获取星期

    var monthsNum = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    var isleapyear = FullYear % 4;        //判断闰年
    if (isleapyear == 0) {
        monthsNum[1] = 29;
    }

    if (day == 0) {
        day = 7;
    }
    var firstDay = day - (date % 7 - 1);       //!important 计算月初星期数

    if (firstDay == 7) {                     //如果月初为七，归零
        firstDay = 0;
    }
    if (firstDay < 0) {                       //如果月初为负，加七循环
        firstDay += 7;
    }

    var f = firstDay;
    for (var j = 1; j <= monthsNum[m]; j++) {
        $("li.month-cell span").eq(f).text(j).parent().addClass("pink");
        f++;
    }
    //当前日期的class
    $("li.month-cell span").eq(firstDay - 1 + date).parent().addClass("blues");
    //显示年月
    $(".month-head span").text(month + "   " + FullYear);
})